<?php
require_once 'ActionFramework/inputs.php';

class TextInputTestCase extends PHPUnit_Framework_TestCase
{
    public function testVanilla()
    {
    	$input = new TextInput('DUMMY_NAME', 'Dummy name');
    	
    	$result = $input->validate('Non-empty');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('S');
    	$this->assertTrue($result['valid']);
    }
    
    public function testNonEmpty()
    {
    	$input = new TextInput('DUMMY_NAME', 'Dummy name', 1);
    	
    	$result = $input->validate('Non-empty');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('S');
    	$this->assertTrue($result['valid']);
    }
    
    
    public function testLongEnough()
    {
    	$input = new TextInput('DUMMY_NAME', 'Dummy name', 5);
    	
    	$result = $input->validate('Non-empty');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('S');
    	$this->assertFalse($result['valid']);
    }
    
    public function testShortEnough()
    {
    	$input = new TextInput('DUMMY_NAME', 'Dummy name', null, 5);
    	
    	$result = $input->validate('Non-empty');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('');
    	$this->assertTrue($result['valid']);
    	
    	$result = $input->validate('S');
    	$this->assertTrue($result['valid']);
    }
    
    public function testCombination()
    {
    	$input = new TextInput('DUMMY_NAME', 'Dummy name', 1, 5);
    	
    	$result = $input->validate('Non-empty');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('');
    	$this->assertFalse($result['valid']);
    	
    	$result = $input->validate('S');
    	$this->assertTrue($result['valid']);
    }
}